<?php

if($user != null)
{
    $stmt = $pdo->prepare("SELECT NAME FROM USERS WHERE ID = ?");
    $stmt->execute(array($user));
    $username = $stmt->fetchObject()->name;
}

if(isset($_POST["logout"]))
{
    unset($_SESSION["user"]);
    header("Location: /");
}

?>
<div id="sidebar">
    <h2>Tervetuloa, <? echo e($username); ?></h2>
    <ul id="menu" class="sidebar">
        <li><a href="?page=calendar">Kalenteri</a></li>
        <li><a href="?page=register">Ilmoittaudu kursseille</a></li>
        <li><a href="?page=registrations">Ilmoittautumiseni</a></li>
        <li><a href="?page=completions">Suoritukseni</a></li>
        <li><a href="?page=failures">Hylätyt kurssini</a></li>
        <li><a href="?page=taught">Opettamani kurssit</a></li>
        <li><a href="?page=supervised">Valvomani ryhmät</a></li>
    </ul>
    <form method="post" action="index.php">
        <input type="submit" name="logout" value="Kirjaudu ulos" />
    </form>
</div>
